# @algorithm @lc id=2102 lang=python3 weekname=biweekly-contest-60
# @title find-the-middle-index-in-array


from cn.Python3.mod.preImport import *
# @test([2,3,-1,8,4])=3
# @test([1,-1,4])=2
# @test([2,5])=-1
# @test([1])=0
class Solution:
    def findMiddleIndex(self, nums: List[int]) -> int:
        tmpSum = sum(nums)
        i, n = 0, len(nums)
        tmp = 0
        while i<n:
            if tmp == tmpSum-tmp-nums[i]:
                return i
            tmp+=nums[i]
            i+=1
        return -1